package sctu.edu.java.year2016.team02.zhoujie.day20160606.chapter11_3;

/**
 * Created by ACER on 2016/6/5.
 */

import java.util.InputMismatchException;
import java.util.Scanner;

public class GreatestCommonDivisor {
    public static void main(String[] args) {
        try {
            Scanner sc = new Scanner(System.in);
            int min;
            int max;
            System.out.print("请输入一个数：");
            min = sc.nextInt();
            System.out.print("请输入另一个数：");
            max = sc.nextInt();
            System.out.println("最大公约数为：" + gongyue(min, max));
        } catch (InputMismatchException e) {
            System.out.println("请输入整数");
        }
    }

    public static int gongyue(int min, int max) {
        while (max % min != 0) {
            int temp = max % min;
            max = min;
            min = temp;
        }
        return min;
    }
}
